
package kaizone.haining.chaobohui.json;

import kaizone.haining.chaobohui.login.User;

import org.json.JSONObject;

import android.content.Context;
import android.text.TextUtils;

public class UserCommentItem extends Item {

    public static final String TYPE_ACT = "ACT";

    public static final String TYPE_NEWS = "NEWS";

    public static final String ACTIVITYID = "activityId";

    public static final String CONTENT = "content";

    public static final String NEWSID = "newsId";

    public static final String STATUS = "status";

    public static final String TARGETNAME = "targetName";

    public static final String TOCOMMENTID = "toCommentId";

    public static final String TOUSERNAME = "toUserName";

    public static final String TYPE = "type";

    public static final String USERNAME = "userName";

    private int activityId;

    private String content;

    private int newsId;

    private String status;

    private String targetName;

    private int toCommentId;

    private String toUserName;

    private String type;

    private String userName;

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getNewsId() {
        return newsId;
    }

    public void setNewsId(int newsId) {
        this.newsId = newsId;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getTargetName() {
        return targetName;
    }

    public void setTargetName(String targetName) {
        this.targetName = targetName;
    }

    public int getToCommentId() {
        return toCommentId;
    }

    public void setToCommentId(int toCommentId) {
        this.toCommentId = toCommentId;
    }

    public String getToUserName() {
        return toUserName;
    }

    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public static UserCommentItem parse(JSONObject jsonObject) {
        UserCommentItem userCommentItem = new UserCommentItem();

        Item item = Item.parse(jsonObject);
        userCommentItem.setItem(item);

        userCommentItem.setActivityId(jsonObject.optInt(ACTIVITYID));
        userCommentItem.setContent(jsonObject.optString(CONTENT));
        userCommentItem.setNewsId(jsonObject.optInt(NEWSID));
        userCommentItem.setStatus(jsonObject.optString(STATUS));
        userCommentItem.setTargetName(jsonObject.optString(TARGETNAME));
        userCommentItem.setToCommentId(jsonObject.optInt(TOCOMMENTID));
        userCommentItem.setUserName(jsonObject.optString(TOUSERNAME));
        userCommentItem.setType(jsonObject.optString(TYPE));
        userCommentItem.setUserName(jsonObject.optString(USERNAME));
        userCommentItem.setToUserName(jsonObject.optString(TOUSERNAME));

        return userCommentItem;
    }

    public String getComment(Context context) {
        StringBuilder comment = new StringBuilder();
        final User my = new User(context);
        String thisUser = "用户";
        String toUser = "用户";
        String userUid = "";
        String toUserUid = "";
        if (!TextUtils.isEmpty(userName)) {
            userUid = "(" + userName.replace("user", "uid:") + ")";
        }//
        if (!TextUtils.isEmpty(toUserName)) {
            toUserUid = "(" + toUserName.replace("user", "uid:") + ")";
        }
        if (!TextUtils.isEmpty(userName) && userName.equals(my.userName)) {
            thisUser = "我";
        }
        if (!TextUtils.isEmpty(toUserName) && toUserName.equals(my.userName)) {
            toUser = "我";
        }
        if (toCommentId > 0) {
            comment.append(thisUser).append(userUid).append("\t回复:\t").append(toUser)
                    .append(toUserUid).append("\t").append(content);
        } else {
            comment.append(thisUser).append(userUid).append("\t:\t").append(content);
        }
        return comment.toString();
    }

    public boolean ableReply(Context context) {
        final User my = new User(context);
        if (!TextUtils.isEmpty(userName) && userName.equals(my.userName)) {
            return false;
        }
        return true;
    }

}
